Version: 22.04.2014
Author: Sebastian Kranz (sebastian.kranz@uni-ulm.de)
Affiliation: Ulm University
The package is currently a research project that contains functions that help to translate .do files, which contain commands of the Stata language, to R. Especially in economics, .do files are very wide spread in empirical analysis. While Stata is a great product, it seems helpful for the advancement of open and reproducible research to be quickly able to translate .do files to R in order to reproduce an empirical analysis in an open source environment.
Unlike Octave, which fully reimplements the Matlab language, the package just helps to translate .do files, resulting in files with valid R syntax. While much translation should work automatically, there will still often be the need to adapt the resulting R file manually. Also, there will still be many features that are not yet implemented.
Before installing translate.do from a local tar.gz file, you should run the following commands to install currently required packages:
# Install packages from CRAN
install.packages("devtools")
install.packages("pryr")
install.packages("dplyr")
install.packages("data.table")
install.packages("lubridate")
# Install packages from github
library(devtools)
install_github(repo = "restorepoint", username = "skranz")
install_github(repo = "stringtools", username = "skranz")
install_github(repo = "sktools", username = "skranz")
# Now install translate.do from local .tar.gz file
After you have installed all required packages, basic usage is simple. Assume you want to translate a file "mydo.do" in a folder "C:\mydofiles". You simply have to run:
library(translate.do)
setwd("C:\mydofiles") # set to the directory with your do file
translate.do.file("mydo.do") # change filename
The function generates a file "mydo.do.r" that contains a translated version of the do file. Consider the following excerpt from a .do file:
clear
use table2_1
sort year month type_fund
merge year month type_fund using table2_2
This .do file code will be automatically translated to the following R code:
.clear()
.use("table2_1")
.sort(year, month, type_fund)
.merge(year, month, type_fund, .using("table2_2"))
The functions .clear, .use, ... are implemented in the package translate.do and try to implement in R the intendet functionality of these commands. Currently, the scope of the package is quite limited:
Nevertheless, frequent commands are already implemented and the package is structured to be easily extended.
Here are some points describing how the package works.
.merge(year, month, type_fund, .using("table2_2"))
.merge = function(...) {
par = rs.par(..., .subst.env = parent.frame())
rs.merge(par)
}
rs.merge = function(par, check.options = TRUE, ...) {
restore.point("rs.merge")
if (check.options)
known.options(par, "using")
# ... ommited code
}
Currently this package is a research project, studying how to facilitate conversion of Stata(TM)* .do files to R. The package uses commands that are inspired by the syntax of .do file commands. At my university, I own a licensed copy of Stata and looked the documentation for .do file syntax. Yet, the package has been written without looking at source code of Stata.
Don't use this package if in your jurisdiction the syntax of a programming language, in particular the syntax of .do file commands, can be protected by copyright and your usage of this package would constitute an infringement of intellectual property of StataCorp. I will not take liability for any misuse of this package.
To the best of my knowledge, programming languages are NOT protected by copyright in the EU and the US. See for example:
http://en.wikipedia.org/wiki/Clone_%28computing%29
*Stata is developed and trademarked by StatCorp
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.